package com.itheima.controller;

import com.itheima.dto.RoleDto;
import com.itheima.dto.RoleMenuDto;
import com.itheima.entry.PageResult;
import com.itheima.entry.QueryPageBean;
import com.itheima.entry.Result;
import com.itheima.pojo.Menu;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import com.itheima.service.RoleService;
import com.itheima.service.UserService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jshstart
 * @creat 2020-11-23 9:44
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Reference
    private RoleService roleService;
    @PostMapping("/findAllRoleByPage")
    public PageResult findAllRoleByPage(@RequestBody QueryPageBean queryPageBean){
       return roleService.findAllRoleByPage(queryPageBean);
    }
    @PostMapping("/addRole")
    public Result addRole(@RequestBody RoleDto roleDto){
        System.out.println("roleDto = " + roleDto);
       boolean flag= roleService.addRole(roleDto);
       return new Result(flag);
    }
    @PostMapping("/distribution")
    public Result distribution(@RequestBody RoleDto roleDto){
        System.out.println("roleDto = " + roleDto);
       boolean flag= roleService.distribution(roleDto);
       return new Result(flag);
    }
    @PostMapping("/addMenu")
    public Result addMenu(@RequestBody RoleMenuDto roleMenuDto){
        System.out.println("roleMenuDto = " + roleMenuDto);
       boolean flag= roleService.addMenu(roleMenuDto);
       return new Result(flag);
    }
    @GetMapping("/findUserByRoleId/{id}")
    public Long[] findUserByRoleId(@PathVariable("id") Long id){
       return roleService.findUserByRoleId(id);
    }
    @GetMapping("/findMenuByRoleId/{id}")
    public Long[] findMenuByRoleId(@PathVariable("id") Long id){
       return roleService.findMenuByRoleId(id);
    }
    @GetMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") Long id){
        System.out.println("id = " + id);
        roleService.deleteById(id);
    }
    @GetMapping("/findAllRole")
    public List<Role> findAllRole() {
        return roleService.findAllRole();
    }

}
